home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Leser 15 / Amiga Plus Leser CD 15.iso / Tools / Hardware / BlizKick / Modules / NewAlert.ASM < prev    next >
Encoding:
Assembly Source File  |  2002-03-13  |  9.2 KB  |  338 lines

  1. ; FILE: Source:modules/NewAlert.ASM          REV: 6 --- Display more info on Alert
  2.  
  3. *
  4. * Modified by Harry Sintonen.
  5. *
  6. *   2.4.97  v2.0: removed self-modifying code.
  7. *  11.9.00  v2.1: slightly improved the code in general, added MMU aware
  8. *                 address zero clearing.
  9. *
  10.  
  11. ; NewAlert - Shows the Taskname within an Alert
  12. ; © Jens Lorenz 1997
  13. ; © Harry Sintonen 2000
  14. ;
  15. ; very strongly based upon:
  16.  
  17. ;
  18. ; Example BlizKick Module
  19. ; ~~~~~~~~~~~~~~~~~~~~~~~
  20. ; This code shows how to create replacing BlizKick "Module".
  21. ; Should be quite self-explonary... (?)
  22. ;
  23. ; !CODE MUST BE FULLY PC-RELATIVE!
  24. ;
  25. ; Written by Harry Sintonen.
  26. ; This source code is Public Domain.
  27.  
  28.         incdir  "include:"
  29.         include "exec/execbase.i"
  30.         include "exec/nodes.i"
  31.         include "exec/tasks.i"
  32.         include "exec/alerts.i"
  33.         include "dos/dosextens.i"
  34.         include "blizkickmodule.i"              ; Some required...
  35.  
  36. _LVOSupervisor          EQU   -$1E
  37. _LVORawDoFmt            EQU   -$20A
  38. _LVOOpenLibraryTagged   EQU   -$32A
  39. _LVOTimedDisplayAlert   EQU   -$336
  40. _LVOCloseLibrary        EQU   -$19E
  41.  
  42.  
  43.         SECTION MODULE,CODE
  44.  
  45. _DUMMY_LABEL
  46.         BK_MOD BKMF_ReplaceMode!BKMF_ExtResBuf,_end,(RTF_COLDSTART)<<24+39<<16+NT_UNKNOWN<<8+$C9,_name,_name,_init
  47.  
  48. ; Replace mode on, requires EXTRESBUF buffer, COLDSTART module, requires KS V39.x or better,
  49. ; module type NT_UNKNOWN, priority -55.
  50.  
  51. STACKBUF        EQU   300                       ; +100 - just to be safe ...
  52.  
  53. ;  IN: a6 = execbase
  54.         dc.l    'NewA'                          ; magic ID (don't change or move!)
  55. _init   bsr.w   clear0                          ; clear 0 longword (don't move! must be .w!)
  56.         movem.l d2/d3/a2/a3/a6,-(sp)        ; the movem must be at _init + 4 !
  57.  
  58.         move.l  LastAlert(a6),d2
  59.         moveq   #-1,d0                          ; Display no alert?
  60.         sub.l   a2,a2                           ; return code = 0
  61.         cmp.l   d0,d2
  62.         beq     .exit
  63.  
  64.         lea     -STACKBUF(sp),sp
  65.         move.l  sp,a3
  66.  
  67.         ; default: 'Software Failure'
  68.         lea     SoftFail(pc),a0
  69.         move.l  d2,d0
  70.         swap    d0
  71.         cmp.b   #(AG_NoMemory>>16),d0
  72.         bne.b   .skip0
  73.         ; 'not enough memory'
  74.         lea     NoMem(pc),a0
  75.         bra.b   .skip1
  76. .skip0
  77.         tst.l   d2                              ; AT_DeadEnd set?
  78.         bmi.b   .skip1
  79.         tst.w   d0                              ; general purpose alert code defined?
  80.         beq.b   .skip1
  81.         ; 'Recoverable Alert'
  82.         lea     Recoverable(pc),a0
  83. .skip1
  84.         bsr     .dostr
  85.         lea     PressLeftie(pc),a0
  86.         bsr     .dostr
  87.         lea     Copyright(pc),a0
  88.         bsr     .dostr
  89.  
  90.         clr.b   (a3)+                           ; put x-pos upper
  91.         lea     ErrorFmt(pc),a0
  92.         lea     LastAlert(a6),a1
  93.         lea     .PutChar(pc),a2
  94.         jsr     _LVORawDoFmt(a6)
  95.         lea     37(a3),a3                       ; Adjust a3
  96.         st      (a3)+
  97.  
  98. * decode the TaskName / CLICommandName *
  99.         lea     NoTask(pc),a2                   ; No Task
  100.         move.l  (LastAlert+4)(a6),d0            ; ^Task -> d0
  101.         beq     .fmttaskname                    ; if 0
  102.         move.l  d0,a0                           ; Task/Process
  103.         cmp.b   #NT_TASK,LN_TYPE(a0)            ; is it a task?
  104.         beq.b   .task                           ; no CLI-Checking needed
  105.  
  106.         ; ok, it's a process, check if it's a CLI too
  107.  
  108.         move.l  pr_CLI(a0),d0                   ; process.cli -> d0
  109.         beq.b   .task                           ; no cli-struct -> get the Taskname
  110.         subq.l  #8,sp
  111.         move.l  pr_TaskNum(a0),(sp)             ; store process.tasknum
  112.         lsl.l   #2,d0                           ; d0 was a BPTR !!!
  113.         move.l  d0,a0                           ; BADDR(process.cli) -> a0
  114.         move.l  cli_CommandName(a0),d0          ; cli.commandname -> a0
  115.         beq.b   .nocliname                      ; NULL name? hs
  116.         move.l  d0,4(sp)                        ; cli.commandname -> ArgArray
  117.         lsl.l   #2,d0                           ; d0 was a BSTR
  118.         move.l  d0,a0
  119.         tst.b   (a0)                            ; Length = 0 ?
  120.         bne.b   .fmtcliname                     ;  -> got CommandName there
  121.  
  122. .nocliname
  123.         lea     NoCLIName(pc),a0                ; get the errorstring
  124.         move.l  a0,d0
  125.         lsr.l   #2,d0                           ; -> BPTR
  126.         move.l  d0,4(sp)
  127. ;        bra.b   .fmtcliname
  128.  
  129. * Format the CLICommandName + CLI-Number *
  130. .fmtcliname
  131.         lea     CLINameFmt(pc),a0
  132.         move.l  sp,a1
  133.         lea     .PutChar(pc),a2
  134.         jsr     _LVORawDoFmt(a6)
  135.         addq.l  #8,sp
  136.         bra.b   .display                        ; display the alert
  137.  
  138. * It's a task *
  139. .task
  140.         lea     NoTaskName(pc),a2               ; default: No TaskName
  141.         move.l  LN_NAME(a0),d0                  ; tc.ln.name = NULL ?
  142.         beq.b   .fmttaskname
  143.         move.l  d0,a0
  144.         tst.b   (a0)                            ; Len = 0 ?
  145.         beq.b   .fmttaskname
  146.         move.l  a0,a2                           ; use the tc.ln.name
  147.  
  148. * Format the TaskName *
  149. .fmttaskname
  150.         lea     TaskNameFmt(pc),a0
  151.         move.l  a2,-(sp)                        ; a2 = ^TaskName
  152.         move.l  sp,a1
  153.         lea     .PutChar(pc),a2
  154.         jsr     _LVORawDoFmt(a6)
  155.         addq.l  #4,sp
  156. ;        bra.b  .display
  157.  
  158. .display
  159.         moveq   #3,d0                           ; 3=intuition.library
  160.         jsr     _LVOOpenLibraryTagged(a6)       ; if this fails we're fucked anyway :-)
  161.         move.l  (LastAlert+3*4)(a6),a1          ; alert timeout
  162.         move.l  a6,a3
  163.         move.l  d0,a6
  164.         move.l  d2,d0                           ; alert number
  165.         move.l  sp,a0                           ; alert string
  166.         moveq   #70,d1                          ; alert y-size
  167.         jsr     _LVOTimedDisplayAlert(a6)
  168.         move.l  d0,a2
  169.         move.l  a6,a1
  170.         move.l  a3,a6
  171.         jsr     _LVOCloseLibrary(a6)
  172.  
  173.         lea     STACKBUF(sp),sp
  174.  
  175.         bsr     clear0                          ; clear 0 longword
  176.  
  177.         moveq   #-1,d0                          ; No alert on next round, please!
  178.         move.l  d0,LastAlert(a6)
  179.  
  180. .exit   move.l  a2,d0
  181.         movem.l (sp)+,d2/d3/a2/a3/a6
  182.         rts
  183.  
  184. * Copy the whole String *
  185. .dostr  clr.b   (a3)+
  186. .copy   move.b  (a0)+,(a3)+
  187.         bne.b   .copy
  188.         st      (a3)+
  189.         rts
  190.  
  191. * Copy one Char *
  192. .PutChar
  193.         move.b  d0,(a3)+
  194.         clr.b   (a3)
  195.         rts
  196.  
  197. ; routine that makes sure the longword at position 0 is really set
  198. ; to zero. (Blizzard PPCs have MMU setup active at alert.hook time!)
  199.  
  200. ;  IN: a6 = execbase
  201. ; OUT: d1/a0/a1 trashed
  202. clear0    btst    #3,$129(a6)        ; do we have 68040 or 68060?
  203.     beq.b    .no040plus
  204.  
  205.     move.l    a5,a0
  206.     lea    .clrit(pc),a1
  207.     lea    runnommu_s(pc),a5
  208.     jsr    _LVOSupervisor(a6)
  209.     move.l    a0,a5
  210. .no040plus
  211. .clrit    clr.l    (0).w
  212.     rts
  213.  
  214. ;  IN: a1 = routine to run in supervisor, mmu disabled, end with rts
  215. ;      d0/d2-d7/a0/a2-a4 = whatever you like
  216. ;      a6 = execbase
  217. ; OUT: d1 = trashed
  218. ;      d0/d2-d7/a0/a2-a4 = whatever you like
  219. ;
  220. runnommu_s
  221.     ori.w    #$700,sr
  222.  
  223.     movec    tc,d1
  224.     move.l    d1,-(sp)
  225.     movec    cacr,d1
  226.     move.l    d1,-(sp)
  227.     movec    dtt1,d1
  228.     move.l    d1,-(sp)
  229.     movec    dtt0,d1
  230.     move.l    d1,-(sp)
  231.     movec    itt1,d1
  232.     move.l    d1,-(sp)
  233.     movec    itt0,d1
  234.     move.l    d1,-(sp)
  235.     cpusha    bc            ;make sure the above is written
  236.     cinva    bc
  237.  
  238.     move.l    #$00FFC000,d1        ;mark 32-bit: Cacheable, Writethrough
  239.     movec    d1,itt0    
  240.     movec    d1,itt1
  241.     movec    d1,dtt1
  242.     move.l    #$0000C040,d1        ;mark 24-bit-DMA: Cache-Inhibited, Precise Exception Model
  243.     movec    d1,dtt0
  244.     move.l    #$80008000,d1        ;instcache + datacache
  245.     movec    d1,cacr
  246.     moveq    #0,d1            ;turn off possible MMU mapping
  247.     pflusha
  248.     movec    d1,tc
  249.     cpusha    bc
  250.     cinva    bc
  251.  
  252.     jsr    (a1)
  253.  
  254.     cpusha    bc
  255.     move.l    (sp)+,d1
  256.     movec    d1,itt0
  257.     move.l    (sp)+,d1
  258.     movec    d1,itt1
  259.     move.l    (sp)+,d1
  260.     movec    d1,dtt0
  261.     move.l    (sp)+,d1
  262.     movec    d1,dtt1
  263.     move.l    (sp)+,d1
  264.     movec    d1,cacr
  265.     move.l    (sp)+,d1
  266.     pflusha
  267.     movec    d1,tc
  268.     cpusha    bc
  269.     cinva    bc
  270.     nop
  271.     rte
  272.  
  273.  
  274. ************** Data **************
  275.  
  276. _name   dc.b    'alert.hook',13,10,0
  277.  
  278.         CNOP    0,4                             ; we make BPTR of NoCLIName..
  279. NoCLIName
  280.         dc.b    18,'» No CommandName «',0
  281.  
  282. APOS1   MACRO
  283.         IFNE    ((\1)>>8)
  284.         FAIL    APOS1: x-position can't be >255 !
  285.         MEXIT
  286.         ENDC
  287.         dc.b    ((\1)&$ff),(\2)
  288.         ENDM
  289. APOS2   MACRO
  290.         IFEQ    ((\1)>>8)
  291.         FAIL    APOS2: x-position can't be <256 !
  292.         MEXIT
  293.         ENDC
  294.         dc.b    ((\1)>>8),((\1)&$ff),(\2)
  295.         ENDM
  296.  
  297. NoMem   APOS1   38,15
  298.         dc.b    'not enough memory.',0
  299. SoftFail
  300.         APOS1   38,15
  301.         dc.b    'Software Failure.',0
  302. Recoverable
  303.         APOS1   38,15
  304.         dc.b    'Recoverable Alert.',0
  305. EBTrashed
  306.         APOS1   38,15
  307.         dc.b    'ExecBase Trashed.',0
  308. Copyright
  309.         APOS1   38,60
  310.         dc.b    '(NewAlert by Jens Lorenz 1997 & Harry Sintonen 2000)',0
  311. PressLeftie
  312.         APOS1   234,15
  313.         dc.b    'Press left mouse button to continue.',0
  314. ErrorFmt
  315.         APOS1   142,30
  316.         dc.b    'Error:  %04x %04x   Task: %08lx',0
  317.  
  318. TaskNameFmt
  319.         APOS2   270,45
  320.         dc.b    'TaskName: %-35.35s',0
  321. CLINameFmt
  322.         APOS2   270,45
  323.         dc.b    'CLI #%-3.3ld: %-35.35b',0
  324.  
  325. NoTask
  326.         dc.b    '» No Task «',0
  327. NoTaskName
  328.         dc.b    '» No TaskName «',0
  329.  
  330.         CNOP    0,2
  331. _end
  332.  
  333.  
  334.    SECTION  VERSION,DATA
  335.  
  336.         dc.b    '$VER: alert.hook_MODULE 2.1 (11.9.00)',0
  337.  
  338.